﻿using Microsoft.AspNetCore.Mvc;
using Tauren.Business.Entity.Input;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.TenantInformation;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 租户信息接口
    /// </summary>
    [Route("api/tenantinfo"), ApiVersion("1.0")]
    [ApiController]
    public class TenantInformationController : ControllerBase
    {
        /// <summary>
        /// 逻辑服务
        /// </summary>
        public ITenantInformationService service { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        public TenantInformationController(ITenantInformationService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 新增租户
        /// </summary>
        /// <param name="tenant">租户信息</param>
        /// <returns></returns>
        [HttpPost,Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] TenantInformation_Input tenant) => service.Add(tenant).ToJsonResult();


        /// <summary>
        /// 编辑租户
        /// </summary>
        /// <param name="tenant">租户信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/editor")]
        public IActionResult Editor([FromBody] TenantInformation_Input tenant) => service.Editor(tenant).ToJsonResult();

        /// <summary>
        /// 删除租户
        /// </summary>
        /// <param name="auotId">租户id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del")]
        public IActionResult Delete([FromQuery] int auotId) => service.Delete(auotId).ToJsonResult();

        /// <summary>
        /// 删除租户--根据租户ID
        /// </summary>
        /// <param name="code">租户编码</param>
        /// <returns></returns>
        [HttpDelete, Route("v{version:apiVersion}/delete")]
        public IActionResult DeleteByCode([FromQuery] string code) => service.DeleteByCode(code).ToJsonResult();

        /// <summary>
        /// 根据Id获取数据
        /// </summary>
        /// <param name="autoId">租户id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get")]
        public IActionResult Get([FromQuery] int autoId) => service.Get(autoId).ToJsonResult();

        /// <summary>
        /// 根据code获取数据
        /// </summary>
        /// <param name="code">租户编码</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/getcode")]
        public IActionResult GetByCode([FromQuery] string code) => service.GetByCode(code).ToJsonResult();

        /// <summary>
        /// 获取所有的租户信息
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/all")]
        public IActionResult All() => service.All().ToJsonResult();
    }
}
